package MyApp.View.wellGroup
{
	import MyApp.Context;
	import MyApp.Model.LoginUser;
	import MyApp.Model.Well;
	import MyApp.Model.proxy.WellGroupProxy;
	import MyApp.MyAppFacade;
	
	import components.wellGroup.AddWell;
	import components.wellGroup.WellGroupWindow;
	
	import flash.events.MouseEvent;
	
	import mx.events.CloseEvent;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import util.Constants;
	import util.GDUtil;
	
	public class AddWellMediator extends Mediator
	{
		public static const NAME:String=GDUtil.getUID();
		public function AddWellMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			view.addEventListener(CloseEvent.CLOSE,doClose);
			view.addEventListener(AddWell.DO_SAVE,doSave);
		}
		private function get view():AddWell{
			return viewComponent as AddWell;
		}
		protected function doSave(e:MouseEvent):void{
			view.currentState="loading";
			var lu:LoginUser=Context.instance.getProperty(Constants.LOGINUSER_KEY) as LoginUser;
			var w:Well=view.w;
			w.owner=lu.name;
			w.groupId=view.wg.wellGroupId;
			this.sendNotification(WellGroupWindow.DO_ADD_WELL,{well:w,pager:view.pager});
		}
		protected function doClose(e:CloseEvent):void{
			MyAppFacade.closePopUpWindow(view,NAME);
		}
		override public function listNotificationInterests():Array{
			return [WellGroupProxy.ADD_W_OK];
		}
		override public function handleNotification(notification:INotification):void{
			switch(notification.getName()){
				case WellGroupProxy.ADD_W_OK:
					MyAppFacade.closePopUpWindow(view,NAME);
					break;
			}
		}
	}
}